作者:手机用户2502929291_707 | 来源:互联网 | 2023-09-18 14:58
一、查看微信告警信息###---查看微信告警配置是否生效###---通过企业微信接收告警信息~~~——http:alert.test.com——status配置是否生效——C
一、查看微信告警信息
### --- 查看微信告警配置是否生效
### --- 通过企业微信接收告警信息
~~~ ——>http://alert.test.com/——>status配置是否生效——>Config
二、Prometheus自定义告警模板
### --- 微信告警模板
[root@k8s-master01 Alarm]# vim wechat.tmpl
{{ define "wechat.default.message" }}
{{ if gt (len .Alerts.Firing) 0 -}}
Alerts Firing:
{{ range .Alerts }}
告警级别:{{ .Labels.severity }}
告警类型:{{ .Labels.alertname }}
故障主机: {{ .Labels.instance }}
Job名称: {{ .Labels.job }}
告警详情: {{ .Annotations.message }}
触发时间: {{ .StartsAt.Format "2006-01-02 15:04:05" }}
{{- end }}
{{- end }}
{{ if gt (len .Alerts.Resolved) 0 -}}
Alerts Resolved:
{{ range .Alerts }}
告警级别:{{ .Labels.severity }}
告警类型:{{ .Labels.alertname }}
故障主机: {{ .Labels.instance }}
Job名称: {{ .Labels.job }}
告警主题: {{ .Annotations.message }}
触发时间: {{ .StartsAt.Format "2006-01-02 15:04:05" }}
恢复时间: {{ .EndsAt.Format "2006-01-02 15:04:05" }}
{{- end }}
{{- end }}
告警链接:'http://alert.test.com'
{{- end }}
### --- 移动到挂载目录下
[root@k8s-master01 Alarm]# cp wechat.tmpl /etc/alertmanager/config/
三、在alertmanager-secrets下定义模板参数
### --- 定义模板参数
[root@k8s-master01 Alarm]# vim alertmanager-secrets.wechat.yaml
# ~~~ 增加微信告警模板:
templates:
- '/etc/alertmanager/config/*.tmpl' # 模板来源
# ~~~ 设置发送消息的参数
- name: 'wechat'
wechat_configs:
- send_resolved: true
to_tag: '1'
agent_id: '1000002' # 此行下添加如下内容
message: '{{template"wechat.default.message".}}' # 添加内容:添加这行参数内容;让其消息生效
### --- 重新触发alertmanager-secrets
[root@k8s-master01 Alarm]# kubectl replace -f alertmanager-secrets.wechat.yaml -n monitoring
secret/alertmanager-main replaced
四、查看收到的告警信息
五、创建alertmanager.yaml的secret(使用热更新的方案更新alertmanager的secrets)
### --- 创建alertmanager.yaml的secret
kubectl create secret generic alertmanager-main --from-file=alertmanager.yaml -n monitoring
### --- 之后更改alertmanager.yaml可以使用热加载去更新k8s的secret
kubectl create secret generic alertmanager-main --from-file=alertmanager.yaml -n monitoring --dry-run -o yaml | kubectl replace -f -
Walter Savage Landor:strove with none,for none was worth my strife.Nature I loved and, next to Nature, Art:I warm'd both hands before the fire of life.It sinks, and I am ready to depart
——W.S.Landor